Skip to content

Conversation

macobo
Copy link
Contributor

@macobo macobo commented Jun 26, 2025

What's new:

  • Script update guide
  • Form submission tracking

What's updated:

  • Rewrite docs/script-extensions.md
  • Script feature description docs
  • docs/plausible-script.md
  • docs/troubleshoot-integration.md
  • Proxy documentation
  • Integrations documentation
    • docs/carrd-integration.md
    • docs/shopify-integration.md
    • docs/discourse-integration.md
  • Google tag manager guide
  • NPM library references

TBD:

  • Images (
    • onboarding,
    • img/data-domain-plausible-analytics-script.png,
    • static/img/network-check-if-plausible-is-working.png
    • docs/error-pages-tracking-404.md for goal creation

@macobo macobo force-pushed the scriptv2-docs branch 2 times, most recently from 79dc0df to 61862b8 Compare June 26, 2025 08:58
@macobo macobo force-pushed the scriptv2-docs branch 4 times, most recently from 60061c4 to ef8d8f7 Compare August 28, 2025 07:13
@@ -24,7 +39,7 @@ proxy_cache_path /var/run/nginx-cache/jscache levels=1:2 keys_zone=jscache:100m
server {

resolver 9.9.9.9; # Use quad9 DNS resolver. Remove this line if you've already configured a DNS resolver.
set $plausible_script_url https://plausible.io/js/script.js; # Change this if you use a different variant of the script
set $plausible_script_url https://plausible.io/js/pa-XXXXX.js; # Change this to path from step 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: maybe remove caching instructions

Comment on lines +14 to +22
function queryStrippedUrl() {
return location.href.split('?')[0]
}

```html
<!-- define the `plausible` function to manually trigger events -->
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
```

Once that's done, you can create another script in which you will trigger your pageview event. This is where you can override the URL property sent to Plausible and prevent the tracking of UTM tags. To do so, add the following snippet:

```html
<!-- trigger pageview -->
<script>
function queryStrippedUrl() {
return location.href.split('?')[0]
}
plausible('pageview', { u: queryStrippedURL() })
</script>
```
function transformRequest(payload) {
// Sets url for the event manually
payload.u = queryStrippedUrl()
return payload
}
Copy link
Contributor

@apata apata Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Because location may have changed between event collection and the time queryStrippedUrl is called, I suggest we rely on the url in the payload:

function transformRequest(payload) {
  var parts = payload.u.split('?')
  var urlWithoutQuery = parts.shift()
  
  if (payload.h) {
    var fragment = parts.join('?').split('#')[1]
    urlWithoutQuery = typeof fragment === 'string'
      ? urlWithoutQuery + '#' + fragment
      : urlWithoutQuery
  }
  
  payload.u = urlWithoutQuery
  return payload
}

Comment on lines -133 to +126
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
<script>
```javascript
function redactedUrl() {
var url = window.location.href;
// Replace every all-numeric sequences located between two slashes by "_ID_"
var redactedUrl = url.replace(/\/\d+\//g, "/_ID_/");
// Send the pageview event to Plausible
plausible('pageview', { u: redactedUrl + window.location.search});
</script>
return url.replace(/\/\d+\//g, "/_ID_/");
}

function transformRequest(payload) {
payload.u = redactedUrl() + window.location.search
return payload
}

// At the end, update plausible.init call
plausible.init({
transformRequest: transformRequest
})
Copy link
Contributor

@apata apata Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This may use stale location, giving inaccurate pageviews, and it also breaks if hashBasedRouting is true. I think we should tune this a bit, along the lines of https://github.com/plausible/docs/pull/614/files#r2314455677

Comment on lines +85 to +88
if (canonicalMeta) {
payload.u = canonicalMeta.href + window.location.search
}
return payload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants